<?php
    require ('../api/config.php');
    //检测是否登陆
    if(!$username)
 	{
	    $url="../login.php";
    	Header("HTTP/1.1 303 See Other");
    	Header("Location: $url");
    	exit;
	}

    if($state!='6')
    {
        echo '<script> alert("你没有权限访问，只有管理员赋予的权限才能访问！");window.location.href="../"</script>';
        exit;
    }
    $cat = isset($_GET['cat']);
?>
<html>
	<head>
		<meta charset="utf-8">
		<title>用户管理 | TOP图片收集管理系统</title>
		<link rel="stylesheet" type="text/css" href="../style/css/user.css"/>
	</head>
	<body>
		<div id="admin" style="padding: 10px;">
			<div id="tit" style="margin-left: 10px;line-height: 30px;">
				<h2>TOP图片收集管理系统 | 用户管理</h2>
			</div>
		</div>
		
		<div id="admin">
			<div id="tit">
				<li>管理</li>
			</div>
			<div class="admin">
				<div id="admin-a">
					<a href="user.php"><button>全部账号信息表</button></a>
					<a href="user.php?cat=3"><button style="background-color: rgba(220,20,60,0.8);">查看封号账号</button></a>
					<a href="user.php?cat=1"><button style="background-color: rgba(30,144,255,0.8);">查看创作者账号</button></a>
					<a href="user.php?cat=0"><button style="background-color: rgba(80,200,255,0.8);">查看管理员账号</button></a>
					<a href="user.php?cat=2"><button>查看普通账号</button></a>
				</div>
			</div>
		</div>
		
		<div id="admin">
			<div id="tit">
				<li>查询账号</li>
			</div>
			<div class="admin" id="cxzh">
				<div id="admin-a">
					<form action="./user.php" method="post">
						<input type="text" id="from" name="sql" placeholder="请输入查询的账号关键字" />
						<input type="submit" id="go" name="go" value="执行"/>
						
				<?php
				$from = isset($_POST['sql']);
				$go = isset($_POST['go']);
				if($go=='执行' and $from !=NULL){
				$sql =mysqli_query($conn,"SELECT uid, username, email, qqnum, stat, ints FROM users WHERE username LIKE '%".$from."%'");
				$users = mysqli_fetch_array($sql);
				if(!$users){
					$sql =mysqli_query($conn,"SELECT uid, username, email, qqnum, stat, ints FROM users WHERE qqnum LIKE '%".$from."%'");
					$users = mysqli_fetch_array($sql);
				}
				if(!$users){
					echo '<b>查无此账号！</b></form>';
				}
				else{
					echo '<b>查询成功！</b></form>';
					$email=$users["email"];

					$root = $users["stat"];
					if($root=='6'){$qx='管理员';}
					elseif($root=='5'){$qx='创作者';}
					elseif($root=='2'){$qx='普通用户';}
					elseif($root=='1'){$qx='限制登录';}
					elseif($root=='0'){$qx='永久封禁';}
					else{$qx='已注销';}
				echo '<table width="100%" border="1" align="left" frame="hsides" rules="rows" cellpadding="10px" bordercolor="#aaaaaa" >
					<tr>
						<th><img src="http://q4.qlogo.cn/g?b=qq&nk='.$users["qqnum"].'&s=100"></th>
						<th>'.$users["uid"].'</th>
						<th>'.$users["username"].'</th>
						<th>'.$email.'</th>
						<th>'.$users["qqnum"].'</th>
						<th>'.$qx.'['.$root.']</th>
						<th>'.$users["ints"].'</th>
						<th><a href="admin_user.php?user='.$users["uid"].'"><button>管理</button></a></th>
					</tr>
					</table>';
					}
				}
				elseif($go == '执行'){echo '<b>输入查询参数！</b></form>';}
				else{echo '</form>';}
					?>
				</div>
			</div>
		</div>
		
		
		<div id="admin">
			<div id="tit">
				<li>账号信息列表</li>
			</div>
			<div class="admin" id="zhxx">
				<div id="admin-a">
					<table width="100%" border="1" align="left" frame="hsides" rules="rows" cellpadding="10px" bordercolor="#aaaaaa" >
					<tr>
						<th>头像</th>
						<th>ID</th>
						<th>用户名</th>
						<th>邮箱</th>
						<th>QQ</th>
						<th>权限</th>
						<th>积分</th>
						<th>管理</th>
					</tr>
<?php
//$sql = "SELECT id, user, pass, qq, root, jf FROM users";
$sql = "SELECT uid, username, email, qqnum, stat, ints FROM users ORDER BY uid DESC";
mysqli_query($conn,$sql);
$result = $conn->query($sql);
if ($result->num_rows > 0) {// 输出数据
    while($row = $result->fetch_assoc()) {
        $email=$row["email"];
        $root = $row["stat"];
        if($root=='6'){$qx='管理员';}
        elseif($root=='5'){$qx='创作者';}
        elseif($root=='2'){$qx='普通用户';}
        elseif($root=='1'){$qx='限制登录';}
        elseif($root=='0'){$qx='永久封禁';}
        else{$qx='已注销';}

$echo = '  <tr>
			<th><img src="http://q4.qlogo.cn/g?b=qq&nk='.$row["qqnum"].'&s=100"></th>
			<th>'.$row["uid"].'</th>
			<th>'.$row["username"]. '</th>
			<th>'.$email.'</th>
			<th>'.$row["qqnum"].'</th>
			<th>'.$qx.'['.$root.']</th>
			<th>'.$row["ints"].'</th>
			<th><a href="admin_user.php?user='.$row["uid"].'"><button>管理</button></a></th>
		</tr>';
if($cat=='1'){if($root=='5'){echo $echo;}}
elseif($cat=='2'){if($root=='2'){echo $echo;}}
elseif($cat=='3'){if($root=='0' or $root == '1'){echo $echo;}}
elseif($cat=='0'){if($root=='6'){echo $echo;}}
elseif($cat=='4'){if($vipstoptime!='0'){echo $echo;}}
else{echo $echo;}
    }
} else {
    echo "0 结果";
}
// $conn->close();
?>
					</table>
				</div>
			</div>
		</div>
		

	</body>
</html>
